package consultan.vanke.com.fragment;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import consultan.vanke.com.R;
import consultan.vanke.com.adapter.CommonAdapter;
import consultan.vanke.com.adapter.ViewHolder;
import consultan.vanke.com.bean.HomeJumpBean;
import consultan.vanke.com.constant.ConstantLibrary;
import consultan.vanke.com.event.MessageEvent;
import consultan.vanke.com.listener.OnItemClickListener;

public class DfDetailFragment extends BaseFragment {
    @BindView(R.id.lienar_top)
    LinearLayout lienarTop;
    @BindView(R.id.linear_content)
    LinearLayout linearContent;
    @BindView(R.id.recy_list)
    RecyclerView recyList;
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.mapview)
    MapView mapview;
    private View view;
    private List<String> subjectsBeansBottom = new ArrayList<>();
    private CommonAdapter<String> adapterBottom;
    AMap aMap;

    @Override
    protected void initViews() {
    }

    @Override
    protected void initDatas() {
        subjectsBeansBottom.add("111");
        subjectsBeansBottom.add("111");
        subjectsBeansBottom.add("111");
        subjectsBeansBottom.add("111");
        recyList.setLayoutManager(new LinearLayoutManager(_mActivity));
        adapterBottom = new CommonAdapter<String>(_mActivity, subjectsBeansBottom, R.layout.home_item_df_child) {
            @Override
            public void onBindViewHolder(ViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            }

            @Override
            public void convert(ViewHolder holder, String assetBean) {
//                ImageView img_photo = holder.getView(R.id.img_photo);

            }

        };
        recyList.setAdapter(adapterBottom);
        mapview.onCreate(null);
        if (aMap == null) {
            aMap = mapview.getMap();
            aMap.getUiSettings().setZoomControlsEnabled(false);
        }
    }

    @Override
    protected void initEvents() {
        adapterBottom.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@Nullable ViewGroup parent, @Nullable View view, Object o, int position) {
                MessageEvent<HomeJumpBean> messageEvent = new MessageEvent<>();
                messageEvent.setData(new HomeJumpBean(ConstantLibrary.fjFragment, ConstantLibrary.TYPE_TIME_OUT));
                EventBus.getDefault().post(messageEvent);
            }

            @Override
            public boolean onItemLongClick(@Nullable ViewGroup parent, @Nullable View view, Object o, int position) {
                return false;
            }
        });
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mapview.onSaveInstanceState(outState);
    }

    @Override
    protected View initContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.df_detail_fragment, null);
        return view;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        setTranslucentStatusBar();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onResume() {
        super.onResume();
        setTranslucentStatusBar();
    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        pop();
    }

    public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
        private int space;

        public SpacesItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view,
                                   RecyclerView parent, RecyclerView.State state) {
            outRect.left = space;
            outRect.right = space;
            outRect.bottom = space;

            // Add top margin only for the first item to avoid double space between items
//            if (parent.getChildPosition(view) == 0)
            outRect.top = space;
        }
    }
}
